<template>
    <div>
      <h1>注册</h1>
      <form @submit.prevent="register">
        <input v-model="username" type="text" placeholder="用户名" required />
        <input v-model="password" type="password" placeholder="密码" required />
        <button type="submit">注册</button>
      </form>
    </div>
  </template>
  
  <script>

  
  export default {
    name: 'Register',
    data() {
      return {
        username: '',
        password: ''
      };
    },
    methods: {
      register() {
        axios.post('http://localhost:3000/register', {
          username: this.username,
          password: this.password
        })
        .then(response => {
          alert('注册成功');
          this.$router.push('/login');
        })
        .catch(error => {
          console.error('注册失败', error);
        });
      }
    }
  };
  </script>
  